<?php
namespace App\Http\Controllers\Web\Member\User;


use App\Http\Controllers\Web\BaseController;
use Illuminate\Http\Request;
class CompanyController extends BaseController
{
    protected $api_url = [
        'savecompany' => ['post', 'seller/company/savecompany'],
        'checkcompanymoney' => ['post', 'seller/company/checkcompanymoney'],
        'showusercompany' => ['get', 'seller/companymaterial/%d/showusercompany'],
    ];


    protected $request;

    public function __construct(Request $request)
    {
        $this->request = $request;

    }


    /*
     * 商铺资料视图页
     */
    public function index(Request $request)
    {
        // 个人注册账户不允许企业认证
//        if (session('user_personal_enterprise')==0){
//            return redirect()->back();
//        }
        //公司信息读取
        $ret = http_web($this->api_url['showusercompany'],[session('user_id')])->send();

        $data = ['info'=>$ret['data']['data']['company']];
//        dd($data);

        return view('web.user.member.prove',$data);
    }



    /**
     * 卖家中心 — 企业认证
     */
    public function saveInfoAction(Request $request)
    {
        $company_id = intval($request->input('company_id'));

        $params = [
            'company_name' => $request->input('rz_company'),
            'angent' => $request->input('rz_companyname'),
            'organization_code'=>$request->input('organization_code'),
            'reg_location' => $request->input('rz_zhuceaddress'),
            'company_address' => $request->input('rz_companyaddress'),
            'company_tel' => $request->input('rz_companyphone'),
            'bank' => $request->input('rz_kaihuyinhang'),
            'bank_account' => $request->input('rz_yinhangzhanghao'),
            'licence_type' => $request->input('licence_type'),
            'social_unify_number' => $request->input('social_unify_number'),
            'userid' => session('user_id'),
        ];

        if ('multi' == $request->input('licence_type')) {
            $params['agnet_licence'] = $request->input('business_license');
            $params['tax_certificate'] = $request->input('tax_certificate');
            $params['organization_code_certificate'] = $request->input('code_certificate');
        }else{
            $params['agnet_licence'] = $request->input('multi_license');
            $params['tax_certificate'] = null;
            $params['organization_code_certificate'] = null;
        }
        $res = http_web($this->api_url['savecompany'])->send($params);

        return $res;

    }



    /**
     * 卖家中心 — 企业认证第二步打款验证
     */
    public function proveSaveStepAction(Request $request)
    {

        $params = [
            'company_id' => intval($request->input('company_id')),
            'money' => $request->input('money'),
            'userid' => session('user_id'),
        ];

        $res = http_web($this->api_url['checkcompanymoney'])->send($params);

        //改变session中存取的认证状态
        if($res['code'] == 0){
            $request->session()->put('user_identification_type', '2');
            $request->session()->put('user_info.identification_type', '2');
        }

        return $res;

    }





}